package com.sc.controller.ahao;

import com.sc.domain.PayBill;
import com.sc.dto.PayBillCreateDTO;
import com.sc.dto.PayBillPageDTO;
import com.sc.dto.PayBillUpdateDTO;
import com.sc.result.PageResult;
import com.sc.result.Result;
import com.sc.service.PayBillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/pay/bill")
@Api(tags = "账单接口")
@Slf4j
@CrossOrigin
public class PayBillController {

    @Autowired
    PayBillService payBillService;

    @ApiOperation("账单分页查询")
    @GetMapping("/page")
    public Result<PageResult<PayBill>> pageQueryBill(PayBillPageDTO payBillPageDTO) {
        PageResult<PayBill> pageResult = payBillService.pageQueryBill(payBillPageDTO);
        return Result.success(pageResult);
    }

    @PostMapping("/createBill")
    public Result createBill(@RequestBody PayBillCreateDTO requestParam) {
        payBillService.createBill(requestParam);
        return Result.success("添加成功", null);
    }

    @GetMapping("/get/{id}")
    public Result<PayBill> queryBillById(@PathVariable("id") Long id) {
        return Result.success(payBillService.getById(id));
    }

    @PutMapping("/updateBill")
    public Result updateBill(@RequestBody PayBillUpdateDTO requestParam) {
        payBillService.updateBill(requestParam);
        return Result.success("修改成功", null);
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteBill(@PathVariable("id") Long id) {
        return Result.success("删除成功", payBillService.removeById(id));
    }

    @DeleteMapping("/deleteByIds")
    public Result deleteByIds(@RequestBody List<Long> ids) {
        return Result.success("删除成功", payBillService.removeByIds(ids));
    }
}
